class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int ans=INT_MIN;
        int min_presum=0;
        int presum=0;
        for(int x:nums){
            presum+=x;
            ans=max(ans,presum-min_presum);
            min_presum=min(min_presum,presum);
        }
        return ans;
    }
};